package main

import (
	"bufio"
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	for _, url := range os.Args[1:] {
		resp, err := http.Get(url)
		if err != nil {
			fmt.Fprintf(os.Stderr, "err: %v \n", err)
			os.Exit(1)
		}
		//io.copy方法，它就是在文件指针之间直接复制的，不用全读入内存
		out, err := os.Create("./a.txt")
		wt := bufio.NewWriter(out)
		b, err := io.Copy(wt, resp.Body)
		fmt.Println("write", b)
		resp.Body.Close()
		if err != nil {
			fmt.Fprintf(os.Stderr, "reading err:%s：%v", url, err)
			os.Exit(1)
		}
		wt.Flush()
	}
}
